package xcmg.device.web.announcement;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import xcmg.device.infra.BasicController;
import xcmg.device.infra.ErrorCode;
import xcmg.device.service.announcement.BasicAnnouncementAuthService;
import xcmg.device.service.vo.announcement.BasicAnnouncementAuthAddVO;
import xcmg.device.service.vo.announcement.BasicAnnouncementAuthVO;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;
import yb.ecp.fast.infra.infra.PageCommonVO;
import yb.ecp.fast.infra.infra.SearchCommonVO;

@RestController
@RequestMapping("/basicAnnouncementAuth")
public class BasicAnnouncementAuthController extends BasicController {

    @Autowired
    private BasicAnnouncementAuthService basicAnnouncementAuthService;

    @RequestMapping(value = "/listDealer", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult list(@RequestBody SearchCommonVO<BasicAnnouncementAuthVO> condition) throws Exception {
        condition.getFilters().setOrgId(getOrgId());
        PageCommonVO pageCommonVO = basicAnnouncementAuthService.listDealer(condition);
        return actionValueResult(pageCommonVO.getPageInfo());
    }

    @RequestMapping(value = "/listUser", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult listUser(@RequestBody SearchCommonVO<BasicAnnouncementAuthVO> condition) throws Exception {
        condition.getFilters().setOrgId(getOrgId());
        PageCommonVO pageCommonVO = basicAnnouncementAuthService.listUser(condition);
        return actionValueResult(pageCommonVO.getPageInfo());
    }

    @RequestMapping(value = "/listCustomer", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult listCustomer(@RequestBody SearchCommonVO<BasicAnnouncementAuthVO> condition) throws Exception {
        condition.getFilters().setOrgId(getOrgId());
        PageCommonVO pageCommonVO = basicAnnouncementAuthService.listCustomer(condition);
        return actionValueResult(pageCommonVO.getPageInfo());
    }

    @RequestMapping(value = "/saveOpr", method = RequestMethod.POST)
    @FastMappingInfo(needLogin = true)
    public ActionResult saveOpr(@RequestBody BasicAnnouncementAuthAddVO addVO) throws Exception {
        try {
            return actionResult(basicAnnouncementAuthService.saveOpr(addVO, getUserId(), getUserName()));
        } catch (Exception e) {
            return new ActionResult(ErrorCode.Failure.getCode(), e.getMessage());
        }
    }

}
